﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.DBUtility;
using System.IO;
using DQYT.HTDZ.Common;
using System.Data;
namespace SkWeb.RiskDB
{
    public partial class FXGJ_Handler : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string Action = "";
                string result = "{\"success\":true}";
                if (!string.IsNullOrEmpty(Request.QueryString["action"]))//获取form的Action中的参数
                {
                    Action = Request.QueryString["action"].Trim().ToLower();//去掉空格并变小写
                }
                switch (Action)
                {
                    case "add":
                       // if (!string.IsNullOrEmpty(Request.Form["name"]))//获取form中的参数
                        {
                          
                            string strJb =Request.Form["jb"];
                            string strGy=Request.Form["gy"];
                            string strRank = Request.Form["rank"];
                          
                            string strSql = "insert into tb_riskmanage_info(jb,gy,rank) values('" + strJb + "','" +strGy + "'," + strRank + ")";
                            if (DbHelperOra.ExecuteSql(strSql) != 1)
                            {
                                result = string.Concat("{\"success\":false, \"msg\":\"", "插入出错，请联系管理员", "\"}");
                            }
                        }
                        break;
                    case "update":
                        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                        {
                            string strId = Request.QueryString["id"];
                            string strJb = Request.Form["jb"];
                            string strGy = Request.Form["gy"];
                            string strRank = Request.Form["rank"];
                       
                            string strSql = "update  tb_riskmanage_info set  jb='" + strJb + "',gy='" + strGy + "',rank='" + strRank + "'  where id =" +strId;
                            if (DbHelperOra.ExecuteSql(strSql) != 1)
                            {
                                result = string.Concat("{\"success\":false, \"msg\":\"", "更新出错，请联系管理员", "\"}");
                            }
                        }
                        break;
                    case "delete":
                        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                        {
                            string strSql = "delete from tb_riskmanage_info where id =" + Request.QueryString["id"];
                            if (DbHelperOra.ExecuteSql(strSql) != 1)
                            {
                                result = string.Concat("{\"success\":false, \"msg\":\"", "删除出错，请联系管理员", "\"}");
                            }
                        }
                        break;
                    case "query":
                        {
                            string format = "\"total\":{0}, \"rows\":{1}";
                            DataTable dt = OracleHelper.Query("select id,jb,gy,rank from tb_riskmanage_info").Tables[0];
                            int recordCount = dt.Rows.Count;
                            result = JsonHelper.ToJson(dt);
                            result = "{" + string.Format(format, recordCount,
                                string.IsNullOrWhiteSpace(result) ? "[]" : result) + "}";
                        }
                        break;
                }

                Response.ContentType = "text/plain";
                Response.Write(result);
                Response.End();

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}